const prefix = "/system/beauty";

var weekIds;
getWeekList();

function load() {
    $('#exampleTable')
        .bootstrapTreeTable(
            {
                id : 'deptId',
                code : 'deptId',
                parentCode : 'parentId',
                type : "GET", // 请求数据的ajax类型
                url : prefix + '/beautyClassList', // 请求数据的ajax的url
                ajaxParams : {"weekId":weekIds}, // 请求数据的ajax的data属性
                expandColumn : '1', // 在哪一列上面显示展开按钮
                striped : true, // 是否各行渐变色
                bordered : true, // 是否显示边框
                expandAll : false, // 是否全部展开
                // toolbar : '#exampleToolbar',
                columns: [
                    {
                        title : '编号',
                        field : 'deptId',
                        visible : false,
                        align : 'center',
                        valign : 'center',
                        width : '50px',
                        checkbox : true
                    },
                    {
                        field: 'name',
                        title: '班级名称'
                    },
                    {
                        field: 'score',
                        title: '班级分数',
                        formatter: function (item, index) {
                            if (item.parentId === 0) {
                                return '';
                            } else {
                                return item.score;
                            }
                        }
                    },
                    /*{
                        title: '操作',
                        field: 'id',
                        align: 'center',
                        formatter: function (item, index) {
                            if (item.parentId === 0) {
                                return '';
                            } else {
                                return '<a class="btn btn-primary btn-sm ' + s_view_h + '" href="#" mce_href="#" title="查看" onclick="view(\''
                                    + item.deptId
                                    + '\')">查看</a> ';
                            }
                        }
                    }*/]
            });
}

function reLoad() {
    weekIds = $("#weekId").val();
    load();
}

function reSet() {
    /*$("#createdTimeStart").val(getThisWeek(1));
    $("#createdTimeEnd").val(getThisWeek(7));*/
    weekIds = "";
    getWeekList();
}

function view(id) {
    layer.open({
        type: 2,
        title: '查看',
        maxmin: true,
        shadeClose: false, // 点击遮罩关闭层
        area: ['100%', '100%'],
        content: prefix + '/view/' + id // iframe的url
    });
}

//获取学期
function getWeekList() {
    $.ajax({
        cache : true,
        type : "GET",
        url : "/system/week/list",
        data : {
            "parentId" : "0",
        },
        success : function(data) {
            var html = '';
            if(data != null && data != '') {
                $.each(data, function(i){
                    if(i == 0) {
                        getWeekListFors(this.weekId);
                    }
                    html += '<option value="'+ this.weekId +'">'+ this.weekName +'</option>';
                });
            }
            $("#weekNumber").html(html);
        }
    });
}

function getWeekListFor() {
    var weekId = $("#weekId").val();
    $.ajax({
        cache : true,
        type : "GET",
        url : "/system/week/list",
        data : {
            "parentId" : weekId,
        },
        success : function(data) {
            var html = '';
            if(data != null && data != '') {
                $.each(data, function(){
                    html += '<option value="'+ this.weekId +'">'+ this.weekName +'</option>';
                });
            }
            $("#weekId").html(html);
        }
    });
}

function getWeekListFors(weekId) {
    $.ajax({
        cache : true,
        type : "GET",
        url : "/system/week/list",
        data : {
            "parentId" : weekId,
        },
        success : function(data) {
            var html = '';
            if(data != null && data != '') {
                $.each(data, function(i) {
                    if(i == 0) {
                        weekIds = this.weekId;
                    }
                    html += '<option value="'+ this.weekId +'">'+ this.weekName +'</option>';
                });
                load();
            }
            $("#weekId").html(html);
        }
    });
}
























